
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var state = window.navigator.onLine;
    if (state) {
      console.log('联网的状态');
    }
    else {
      console.log('断网的状态');
    }
  </script>
</body>
</html>